package org.hsieh.tr.explore.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.hsieh.tr.explore.dbsource.IDatabaseInfo;
import org.hsieh.tr.explore.ui.DatabaseViewer;
import org.hsieh.tr.explore.util.JFaceUtil;

public class EditConnectionAction implements IViewActionDelegate {

    private DatabaseViewer viewer = null;

    private IDatabaseInfo selectedInfo = null;

    public void init(IViewPart view) {
	viewer = (DatabaseViewer) view;
    }

    public void run(IAction action) {
	viewer.editSelectedInfo();
    }

    public void selectionChanged(IAction action, ISelection selection) {
	Object fristSelected = JFaceUtil.getFristSelected(selection);
	if (fristSelected instanceof IDatabaseInfo) {
	    selectedInfo = (IDatabaseInfo) fristSelected;
	    action.setEnabled(selectedInfo != null);
	} else {
	    action.setEnabled(false);
	}
    }

}
